package interfaces.mainpanel.gui;

import interfaces.subpanel.cargardatos.gui.LoadDataSetGUI;
import interfaces.subpanel.classifier.ClassifierGUI;
import interfaces.subpanel.clustering.gui.ClusteringGUI;
import interfaces.subpanel.preprocesamiento.gui.PreprocessingGUI;
import interfaces.subpanel.summaryinfo.gui.SummaryInfoGUI;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

public class TesisMainGUI extends JPanel {

	private static final long serialVersionUID = 1L;

	private LoadDataSetGUI loadDataSetGUI;

	private PreprocessingGUI preprocessingGUI;

	private ClassifierGUI classifierGUI;

	private ClusteringGUI clusteringGUI;
	
	private SummaryInfoGUI summaryInfoGUI;
	
	public TesisMainGUI() {
		super(new GridLayout(1, 1));

		JTabbedPane tabbedPane = new JTabbedPane();
		ImageIcon iconUpload = new ImageIcon(this.getClass().getResource("/upload.png"));
		ImageIcon iconPreprocessing = new ImageIcon(this.getClass().getResource("/dataPreprocessing.png"));
		ImageIcon iconClassify = new ImageIcon(this.getClass().getResource("/statics.png"));
		ImageIcon iconClustering = new ImageIcon(this.getClass().getResource("/clustering.png"));
		ImageIcon iconResults = new ImageIcon(this.getClass().getResource("/results50.png"));

		this.loadDataSetGUI = new LoadDataSetGUI(this);
		tabbedPane.addTab("Data Loading", iconUpload, loadDataSetGUI);

		this.preprocessingGUI = new PreprocessingGUI(this);
		tabbedPane.addTab("Data Pre-processing", iconPreprocessing, preprocessingGUI);

		this.classifierGUI = new ClassifierGUI(this);
		tabbedPane.addTab("Data Classifiers", iconClassify, classifierGUI);

		this.clusteringGUI = new ClusteringGUI(this);
		tabbedPane.addTab("Data Clustering", iconClustering, clusteringGUI);

		this.summaryInfoGUI = new SummaryInfoGUI(this);
		tabbedPane.addTab("Summary Data", iconResults, summaryInfoGUI);

		add(tabbedPane);
		tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

	}

	private static void setCursorToAllButtons(Container container) {
		Component[] components = container.getComponents();

		for (int i = 0; i < components.length; i++) {
			if (components[i] instanceof Container) {
				setCursorToAllButtons((Container) components[i]);
			}
			if (components[i] instanceof JButton || components[i] instanceof JComboBox) {
				components[i].setCursor(new Cursor(Cursor.HAND_CURSOR));
			}
		}
	}

	private static void createAndShowGUI() {

		JFrame frame = new JFrame("Tesis Dario Boverio");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		TesisMainGUI mainGUI = new TesisMainGUI();
		frame.add(mainGUI, BorderLayout.CENTER);

		frame.pack();
		frame.setSize(new Dimension(1100, 750));
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		setCursorToAllButtons(mainGUI);
	}

	public static void main(String[] args) {

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {
				    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
				        if ("Nimbus".equals(info.getName())) {
				            UIManager.setLookAndFeel(info.getClassName());
				            break;
				        }
				    }
				} catch (Exception e) {
				}
				//UIManager.put("swing.boldMetal", Boolean.FALSE);
				createAndShowGUI();
			}
		});
	}

	public LoadDataSetGUI getLoadDataSetGUI() {
		return loadDataSetGUI;
	}

	public PreprocessingGUI getPreprocessingGUI() {
		return preprocessingGUI;
	}

	public ClassifierGUI getClassifierGUI() {
		return classifierGUI;
	}

	public ClusteringGUI getClusteringGUI() {
		return clusteringGUI;
	}

	public SummaryInfoGUI getSummaryInfoGUI() {
		return summaryInfoGUI;
	}
	
}
